﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <link href="../CSS/style1.css" rel="stylesheet" type="text/css" />
    <link href="../CSS/style4.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.showModalDialog.js" type="text/javascript"></script>
    <script type="text/javascript">
        //得到学员的ID
        var UserID = window.dialogArguments.id;
        $(function () {
            List();
            Load();

        });
        function Load() {
            $.ajax({
                url: "roleManager.asmx/SelectRole",
                type: "post",
                data: JSON.stringify({}),
                dataType: "json",
                contentType: "application/json",
                success: function (obj) {
                    var sel1 = $("#select1");
                    for (var i = 0; i < obj.d.length; i++) {
                        sel1.append('<option value="' + obj.d[i].ID + '">' + obj.d[i].RoleName + '</option>');
                    }
                }, error: function (xmlhttp) {
                    alert("错误：" + xmlhttp.responseText);
                }
            });
        }
        function List() {
            //通过id将资料从数据库中查询出来
            $.ajax({
                url: "userManager.asmx/FindUser",
                type: "post",
                data: JSON.stringify({ id: parseInt(UserID) }),
                dataType: "json",
                contentType: "application/json",
                success: function (obj) {
                    $("#select1").append('<option value="' + obj.d.ID + '">' + obj.d.RoleName + '</option>');
                    $("#txtUserLName").val(obj.d.UserLName);
                    $("#txtUserName").val(obj.d.UserName);
                }, error: function (xmlhttp) {
                    alert("错误：" + xmlhttp.responseText);
                }
            });
        }
        //修改用户名
        function ok() {
            var RoleID = $("#select1").val();
            var UserLName = $("#txtUserLName").val();
            var UserLPWD = $("#txtPwd").val();
            var pwd = $("#txtQr").val();
            var UserName = $("#txtUserName").val();
            if (UserLPWD == pwd) {
                var u = {
                    UserID:UserID,
                    RoleID: RoleID,
                    UserLName: UserLName,
                    UserLPWD: UserLPWD,
                    UserName: UserName
                };
            } else {
                alert("两次输入的密码不一致");
                return;
            }
            //发起更新请求
            $.ajax({
                url: "userManager.asmx/UpdateUser",
                type: "post",
                data: JSON.stringify({ u: u }),
                dataType: "json",
                contentType: "application/json",
                success: function (obj) {
                    alert(obj.d ? "您已修改成功" : "您修改失败，请稍候再试");
                    //刷新
                    window.returnValue = true;
                    window.close();
                }, error: function (xmlhttp) {
                    alert("错误：" + xmlhttp.responseText);
                }
            });

        };
    </script>
</head>
<body>
    <table class="tableEdit">
        <thead>
            <tr>
                <td>登陆用户修改</td>
            </tr>
        </thead>
        <tr>
            <th>角色名称：</th>
            <td>
                <select id="select1">
                
                </select>
            </td>
            <th>用户名称：</th>
            <td><input type="text" id="txtUserLName" style="color:blue;width:120px" /></td>
        </tr>
        <tr>
            <th>用户密码：</th>
            <td><input type="password" id="txtPwd" style="color:blue;width:120px" /></td>
            <th>确认密码：</th>
            <td><input type="password" id="txtQr" style="color:blue;width:120px" /></td>
        </tr>
        <tr>
            <th>真实姓名：</th>
            <td><input type="text" id="txtUserName" style="color:blue;width:120px" /></td>
        </tr>
        <tr>

        </tr>
        <tfoot>
            <tr>
                <td colspan="4" style="text-align:center">
                    <input type="button" value="确定" onclick="ok();" />&nbsp;&nbsp;
                    <input type="button" value="关闭" onclick="window.close()" />
                </td>
            </tr>
        </tfoot>
    </table>
</body>
</html>
